<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
 <head>
  <title>inputEx - DSSelectField Usage</title>

<!-- YUI CSS -->
<link rel="stylesheet" type="text/css" href="../lib/yui/reset-fonts/reset-fonts.css">
<link rel="stylesheet" type="text/css" href="../lib/yui/container/assets/container.css"> 
<link rel="stylesheet" type="text/css" href="../lib/yui/assets/skins/sam/skin.css">

<!-- InputEx CSS -->
<link type='text/css' rel='stylesheet' href='../css/inputEx.css' />

<!-- Demo CSS -->
<link rel="stylesheet" type="text/css" href="css/demo.css"/>
<link rel="stylesheet" type="text/css" href="css/dpSyntaxHighlighter.css">

 </head>

 <body>

<h1>inputEx - DSSelectField Usage</h1>


<!-- Example 1 -->
<div class='exampleDiv'>

	<h2>Using a DataSource</h2>
	
	<p>How to populate the selectField using a <a href="http://developer.yahoo.com/yui/datasource/" target="_new">YUI datasource</a> (from local data, XHR, JSONP, function, ...):</p>

	<div class='demoContainer' id='container1'></div>

	<div class='codeContainer'>
		<textarea name="code" class="JScript">
			var myDataSource = new YAHOO.util.XHRDataSource("books.json"); 
			myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
			myDataSource.responseSchema = { fields: ["id","quantity","amount","title", "category"], resultsList: "Results" };
			
			new inputEx.DSSelectField({name: 'country', datasource: myDataSource, valueKey: "id", labelKey: "title", parentEl: 'container1'});
		</textarea>
	</div>

</div>



<!-- Example 2 -->
<div class='exampleDiv'>

	<h2>Updated event</h2>
	
	<p>How to listen to the updated event :</p>

	<div class='demoContainer' id='container2'></div>

	<div class='codeContainer'>
				<textarea name="code" class="JScript">
					var myDataSource = new YAHOO.util.XHRDataSource("books.json"); 
					myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
					myDataSource.responseSchema = { fields: ["id","quantity","amount","title", "category"], resultsList: "Results" };
					
					var el = YAHOO.util.Dom.get('container2');
					var field2 = new inputEx.DSSelectField({name: 'country', datasource: myDataSource, valueKey: "id", labelKey: "title", parentEl: el});
					
					var logDiv = inputEx.cn('div', null, null, "Log :");
					el.appendChild(logDiv);
					field2.updatedEvt.subscribe(function(e,params) {
						var value = params[0];
						logDiv.innerHTML += "Updated at "+(new Date())+" with value "+value;
						logDiv.appendChild(inputEx.cn('br'));
					});
		</textarea>
			</div>

</div>



<!-- Example 3 -->
<div class='exampleDiv'>

	<h2>Set Value</h2>
	
	<p>How to set the value :</p>

	<div class='demoContainer' id='container3'></div>

	<div class='codeContainer'>
				<textarea name="code" class="JScript">
					var myDataSource = new YAHOO.util.XHRDataSource("books.json"); 
					myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
					myDataSource.responseSchema = { fields: ["id","quantity","amount","title", "category"], resultsList: "Results" };
					
					var el = YAHOO.util.Dom.get('container3');
					var field3 = new inputEx.DSSelectField({name: 'country', datasource: myDataSource, valueKey: "id", labelKey: "title", parentEl: el});
					
					var setValueButton = inputEx.cn('button', null, null, "setValue to po-1482");
					el.appendChild(setValueButton);
					YAHOO.util.Event.addListener(setValueButton, 'click', function(e,params) {
						field3.setValue("po-1482");
					});
		</textarea>
			</div>

</div>


<!-- YUI Library -->
<script type="text/javascript" src="../lib/yui/utilities/utilities.js"></script>
<script type="text/javascript" src="../lib/yui/json/json-min.js"></script>
<script type="text/javascript" src="../lib/yui/datasource/datasource-min.js"></script>

<!-- InputEx -->
<script src="../js/inputex.js"  type='text/javascript'></script>
<script src="../js/mixins/choice.js"  type='text/javascript'></script>
<script src="../js/Field.js"  type='text/javascript'></script>
<script src="../js/fields/SelectField.js"  type='text/javascript'></script>
<script src="../js/fields/DSSelectField.js"  type='text/javascript'></script>

<!-- inputEx examples -->
<script src="js/dpSyntaxHighlighter.js"></script>
<script src="inputex-examples.js"></script>

 </body>
</html>